import csv
import random
from random import shuffle

# 配置参数
START_ID = 101
TOTAL_DATA = 1000
START_TIMESTAMP = 1710892800  #2024-03-20 00:00:00
INTERVAL = 300  # 300秒 = 5分钟

def generate_data():
    data = []
    current_id = START_ID
    remaining = TOTAL_DATA
    
    while remaining > 0:
        # 随机生成当前ID的数据量（1到288之间）
        max_points = min(288, remaining) #min函数返回最小值
        num_points = random.randint(1, max_points) if max_points > 1 else 1 #randint函数返回1到max_points之间的随机整数
        
        # 生成时间序列
        for i in range(num_points):
            timestamp = START_TIMESTAMP + i * INTERVAL
            value = round(random.uniform(1.0, 10.0), 1) #uniform函数返回1.0到10.0之间的随机浮点数
            data.append([current_id, timestamp, value])
        
        remaining -= num_points
        current_id += 1
    
    # 随机打乱所有数据
    shuffle(data)
    return data

# 生成并写入CSV文件
with open('./data.csv', 'w', newline='') as f:
    writer = csv.writer(f)
    writer.writerow(['ID', 'TIMESTAMP', 'VALUE'])
    writer.writerows(generate_data())

print("数据生成完成，总计1000条记录")